Telegram Group & Telegram Channel
Отсутствующие ключи в словаре

При обращении по отсутствующему ключу в словаре мы получим исключение KeyError. Но мы можем переопределить это поведение.

Для этого создадим свой собственный класс словаря, унаследовавшись от dict. После чего нам просто необходимо переопределить метод __missing__, который вызывается в базовой реализации методом dict.__getitem__ при при адресации к отсутствующему ключу.

Мы можем, например, возвращать какое-то дефолтное значение, либо определить любую другую необходимую логику поведения.

#dict



tg-me.com/python_academy/675
Create:
Last Update:

Отсутствующие ключи в словаре

При обращении по отсутствующему ключу в словаре мы получим исключение KeyError. Но мы можем переопределить это поведение.

Для этого создадим свой собственный класс словаря, унаследовавшись от dict. После чего нам просто необходимо переопределить метод __missing__, который вызывается в базовой реализации методом dict.__getitem__ при при адресации к отсутствующему ключу.

Мы можем, например, возвращать какое-то дефолтное значение, либо определить любую другую необходимую логику поведения.

#dict

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/675

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

How to Invest in Bitcoin?

Like a stock, you can buy and hold Bitcoin as an investment. You can even now do so in special retirement accounts called Bitcoin IRAs. No matter where you choose to hold your Bitcoin, people’s philosophies on how to invest it vary: Some buy and hold long term, some buy and aim to sell after a price rally, and others bet on its price decreasing. Bitcoin’s price over time has experienced big price swings, going as low as $5,165 and as high as $28,990 in 2020 alone. “I think in some places, people might be using Bitcoin to pay for things, but the truth is that it’s an asset that looks like it’s going to be increasing in value relatively quickly for some time,” Marquez says. “So why would you sell something that’s going to be worth so much more next year than it is today? The majority of people that hold it are long-term investors.”

The lead from Wall Street offers little clarity as the major averages opened lower on Friday and then bounced back and forth across the unchanged line, finally finishing mixed and little changed.The Dow added 33.18 points or 0.10 percent to finish at 34,798.00, while the NASDAQ eased 4.54 points or 0.03 percent to close at 15,047.70 and the S&P 500 rose 6.50 points or 0.15 percent to end at 4,455.48. For the week, the Dow rose 0.6 percent, the NASDAQ added 0.1 percent and the S&P gained 0.5 percent.The lackluster performance on Wall Street came on uncertainty about the outlook for the markets following recent volatility.

Python Academy from in


Telegram Python Academy
FROM USA